import com.sun.org.apache.regexp.internal.RE;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;

import java.util.HashSet;
import java.util.Set;

/**
 * @Auther: tianchao
 * @Date: 2021/11/27 12:39
 * @Description:
 */
public class SentinelTest {
    public static void main(String[] args) {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(20);
        jedisPoolConfig.setMaxIdle(10);
        jedisPoolConfig.setMinIdle(5);
        String mastName = "mymaster";
        //哨兵地址
        Set<String> sentinels= new HashSet<>();
        sentinels.add(new HostAndPort("192.168.10.200",26379).toString());
        sentinels.add(new HostAndPort("192.168.10.200", 26380).toString());
        sentinels.add(new HostAndPort("192.168.10.200",26381).toString());
        JedisSentinelPool jedisSentinelPool = new JedisSentinelPool(mastName,sentinels , jedisPoolConfig,4000,null);
        Jedis jedis = null;
        try {
            jedis = jedisSentinelPool.getResource();
            System.out.println(jedis.get("hehe"));
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (jedis!=null){
                //不是关闭，是归还给资源池
                jedis.close();
            }
        }
    }
}
